package Test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class Test {

    public static void main(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        arrayList.add(40);

        ListIterator<Integer> listIterator = arrayList.listIterator(2);
        while (listIterator.hasNext()) {
            System.out.print(listIterator.next()+" ");
        }

        System.out.println();

        ListIterator<Integer> listIterator2 = arrayList.listIterator(arrayList.size());
        while (listIterator.hasPrevious()) {
            System.out.print(listIterator.previous()+" ");
        }
    }


    public static void main7(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        arrayList.add(40);
        for(int i=0;i<arrayList.size();i++) {
            System.out.print(arrayList.get(i)+" ");
        }
    }
    public static void main6(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        arrayList.add(40);
        for(Integer i:arrayList) {
            System.out.print(i+" ");
        }
    }


    public static void main5(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        arrayList.add(40);
        System.out.println(arrayList);
        List<Integer> arrayList1=arrayList.subList(1,3);
        System.out.println(arrayList1);

        arrayList1.set(1,99);
        System.out.println("=======set之后=======");
        System.out.println(arrayList);
        System.out.println(arrayList1);
    }

    public static void main4(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(10);
        arrayList.add(20);
        System.out.println(arrayList);
        arrayList.remove(Integer.valueOf(10));
        System.out.println(arrayList);
    }
    public static void main3(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        ArrayList<Integer> arrayList2=new ArrayList<>(0);
    }

    public static void main2(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(10);
        System.out.println(arrayList);
    }


    public static void main1(String[] args) {
        List<Integer> arrayList=new ArrayList<>();
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);

        List<Integer> arrayList2=new ArrayList<>(arrayList);
        System.out.println(arrayList2);
    }
}
